package com.ruoyi.web.controller.emp;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EmpNormAttribute;
import com.ruoyi.system.service.IEmpNormAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 指标属性Controller
 *
 * @author zsl
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/system/attribute")
public class EmpNormAttributeController extends BaseController {
    @Autowired
    private IEmpNormAttributeService empNormAttributeService;

    /**
     * 查询指标属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:list')")
    @GetMapping("/list")
    public AjaxResult list(EmpNormAttribute empNormAttribute) {
        List<EmpNormAttribute> list = empNormAttributeService.selectEmpNormAttributeList(empNormAttribute);
        return success(list);
    }

    /**
     * 导出指标属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:export')")
    @Log(title = "指标属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmpNormAttribute empNormAttribute) {
        List<EmpNormAttribute> list = empNormAttributeService.selectEmpNormAttributeList(empNormAttribute);
        ExcelUtil<EmpNormAttribute> util = new ExcelUtil<EmpNormAttribute>(EmpNormAttribute.class);
        util.exportExcel(response, list, "指标属性数据");
    }

    /**
     * 获取指标属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(empNormAttributeService.selectEmpNormAttributeById(id));
    }

    /**
     * 新增指标属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:add')")
    @Log(title = "指标属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmpNormAttribute empNormAttribute) {
        empNormAttribute.setCreateBy(getUsername());
        return toAjax(empNormAttributeService.insertEmpNormAttribute(empNormAttribute));
    }

    /**
     * 修改指标属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:edit')")
    @Log(title = "指标属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmpNormAttribute empNormAttribute) {
        empNormAttribute.setUpdateBy(getUsername());
        return toAjax(empNormAttributeService.updateEmpNormAttribute(empNormAttribute));
    }

    /**
     * 删除指标属性
     */
    @PreAuthorize("@ss.hasPermi('system:attribute:remove')")
    @Log(title = "指标属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(empNormAttributeService.deleteEmpNormAttributeByIds(ids));
    }
}
